package com.hushui.mall.member.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hushui.mall.member.entity.MemberLoginLogEntity;
import com.hushui.mall.member.service.MemberLoginLogService;
import com.hushui.common.utils.PageUtils;
import com.hushui.common.utils.R;

import javax.servlet.http.HttpServletRequest;


/**
 * 会员登录记录
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-03-16 11:52:43
 */
@RestController
@RequestMapping("member/memberloginlog")
public class MemberLoginLogController {
    @Autowired
    private MemberLoginLogService memberLoginLogService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberLoginLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MemberLoginLogEntity memberLoginLog = memberLoginLogService.getById(id);

        return R.ok().put("memberLoginLog", memberLoginLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MemberLoginLogEntity memberLoginLog){


		memberLoginLogService.save(memberLoginLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberLoginLogEntity memberLoginLog){
		memberLoginLogService.updateById(memberLoginLog);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberLoginLogService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }



//    @RequestMapping("/AAA")
//    public void AAA(HttpServletRequest request){
//
////        String ip = IpUtil.getIpAddress(request);
////
////        String ip = IpUtil.getIp(request);
////        System.out.println(ip);
////        Map cityInfo = IpUtil.getCityInfo(ip);
////        System.out.println(cityInfo.get("province"));
////
////        String ip2 = "183.213.81.138";
////        Map result = IpUtil.getCityInfo(ip2);
////        System.out.println(result.get("province"));
////
////        System.out.println(result.get("city"));
//
//        String ip = IpUtil.getIp(request);
//        Map cityInfo = IpUtil.getCityInfo(ip);
//        if ("中国".equals(cityInfo.get("country"))){
//            System.out.println(cityInfo.get("province"));
//            Object province = cityInfo.get("province");
//
//            System.out.println("中国"+province);
//        }
//        else if ("0".equals(cityInfo.get("country"))){
//            System.out.println(cityInfo);
//            if ("内网IP".equals(cityInfo.get("ISP"))){
//                System.out.println("内网");
//            }
//            System.out.println("未知");
//        }
//        else {
//            System.out.println(cityInfo.get("country"));
//        }
//
//
//    }

}
